# 导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class Mailbox_Operation:
    def __init__(self):
        # 准备配置项
        self.options = webdriver.ChromeOptions()
        self.user_data_dir = r'--user-data-dir=C:\Users\年轻人\AppData\Local\Google\Chrome\User Data'
        self.options.add_argument(self.user_data_dir)
        # 打开浏览器和163邮箱页面
        self.driver = webdriver.Chrome(options=self.options)
        self.driver.get("https://mail.163.com/")
    def method(self):
        self.driver.find_element(By.ID, "_mail_component_149_149").click()
        # 定位收件人输入框,并输入内容
        self.driver.find_element(By.CLASS_NAME, "nui-editableAddr-ipt").send_keys("xiaoxiao_07140714@163.com")
        # 定位主题输入框,并输入内容
        self.driver.find_element(By.XPATH, "//input[@class='nui-ipt-input' and @maxlength='256']").send_keys('录取通知')
        # 切换指定窗口
        self.driver.switch_to.frame(self.driver.find_element(By.CLASS_NAME, "APP-editor-iframe"))
        # 定位文本框,输入内容
        self.driver.find_element(By.XPATH, '//html/body/p').send_keys('你好,肖大能,恭喜你,被大能每天笑哈哈集团录取')
        # 返回主页面
        self.driver.switch_to.default_content()
        # 定位发送按钮,并点击发送
        self.driver.find_element(By.XPATH, "//footer/div/span").click()
    def quit(self):
        time.sleep(10)
        self.driver.quit()

if __name__ == '__main__':
    mo = Mailbox_Operation()
    mo.method()
    mo.quit()

